<?php
namespace app\models;

use app\models\Admin;
use app\models\Model;
use app\models\AuthRole;
use Yii;
use yii\helpers\ArrayHelper;

/**
 * Change password model
 *
 * @property integer $id
 * @property string $username
 * @property string $password
 * @property string $repassword
 */
class AssignUser extends Model
{
    public $username;
    public $password;
    public $repassword;

    /**
      * @inheritdoc
      */
    public function rules()
    {
        return [

            [['username', 'password', 'repassword'], 'required'],

            ['repassword', 'compare', 'compareAttribute' => 'password'],

            [['password', 'repassword'], 'string', 'min' => 5, 'max' => 30],

        ];
    }


    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return
            [
                'username' => '用户名',
                'password' => '密码',
                'repassword' => '确认密码',
            ];
    }

    public function save()
    {
        $model = new Admin();
        $model->username = $this->username;
        $model->created_at = date('Y-m-d H:i:s',time());
        $model->setPassword($this->password);
        $model->generateAuthKey();
        return $model->save();
    }

}
